package com.zyf.chapter01.principle.practice;

/**
 * 将类组装并提供入口
 *
 * @author yifeng
 */
public class Demo {
    public static void main(String[] args) {
        MetricsStorage storage = new RedisMetricsStorage();
        // 第一个入口，触发统计显示
        ConsoleReporter consoleReporter = new ConsoleReporter(storage);
        consoleReporter.startRepeatedReport(60, 60);

        EmailReporter emailReporter = new EmailReporter(storage);
        emailReporter.addToAddress("yifeng@gmail.com");
        emailReporter.startDailyReport();
        // 第二个入口 提供一组 API 来采集原始数据
        MetricsCollector collector = new MetricsCollector(storage);
        collector.recordRequest(new RequestInfo("register", 123, 10244));
        collector.recordRequest(new RequestInfo("register", 223, 10244));
        collector.recordRequest(new RequestInfo("register", 323, 10244));
        collector.recordRequest(new RequestInfo("login", 23, 10244));
        collector.recordRequest(new RequestInfo("login", 2123, 10244));

        try {
            Thread.sleep(100000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
